package persistence;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import persistence.exception.DAOException;
import persistence.util.JdbcUtil;

public class CityDAOJdbcImpl extends JdbcDAOBase implements CityDAO{
	
	public CityDAOJdbcImpl() {
	}
	@Override
	public City find(int id) throws DAOException{
		String sql = "SELECT id, plz, ort FROM orte WHERE id = ?";
			
		Connection con = null;
		PreparedStatement prepStmt = null;
		ResultSet rs = null;
		City city = null;
		
		try {
			con = getConProvider().getConnection();
			prepStmt = con.prepareStatement(sql);
			prepStmt.setInt(1, id);
			rs = prepStmt.executeQuery();
			
			if(rs.next()) {
				city = new City (rs.getInt(1), rs.getInt(2), rs.getString(3));
			}
		}
		catch (SQLException se) {
			throw new DAOException("Problem when attempting to find City with id: " + id, se);
		}
		finally {
			JdbcUtil.cleanup(con, prepStmt, rs);
		}
		return city;
	}

	@Override
	public List<City> findAllByTitle() throws DAOException{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateCity() throws DAOException{
		// TODO Auto-generated method stub
		
	}

	@Override
	public City create() throws DAOException{
		// TODO Auto-generated method stub
		return null;
	}

}
